 const webpack = require('webpack');
 const autoprefixer = require('autoprefixer');
 const config = require('./config'); // 引入配置
 const defPath = config.defPath;
 const APP_PATH = defPath.APP_PATH; // 源码目录

 module.exports = function() {
   return {
     context: defPath.ROOT_PATH, // 设置跟目录为执行环境
     resolve: { // 解析模块请求的选项
       modules: [
         APP_PATH,
         'node_modules'
       ],
       // 用于查找模块的目录
       extensions: [
         '.js', '.json', '.jsx', '.css','.html'
       ],
     },
    //  cache: true, // 启用缓存
     module: { // 公用的加载器
       rules: [
         {
           test: /\.(js|jsx)$/,
           include: APP_PATH,
           loader: 'babel-loader'
         },
         {
          test: /\.tsx?$/,
          loader: 'ts-loader'
         },
       ]
     },
     plugins: [
       // autoprefixer 是 postcss-loader 的 插件，需要在这里进行 autoprefixer 插件的配置
       new webpack.LoaderOptionsPlugin({
         options: {
           context: '/',
           minimize: true,
           postcss: [autoprefixer(config.autoConfig)]
         }
       }),
     ]
   };
 };
